using System;
using System.Runtime.Serialization;

namespace WWB.DisqusSharp.Model.DisqusService
{
    [Serializable]
    public class DisqusServiceException : Exception
    {
        public string ErrorCode { get; private set; }
        
        public DisqusServiceException(string code, string message) : base(message)
        {
            ErrorCode = code;
        }

        public DisqusServiceException(string code, string message, Exception inner) : base(message, inner)
        {
            ErrorCode = code;
        }

        protected DisqusServiceException(
            SerializationInfo info,
            StreamingContext context) : base(info, context)
        {
        }
    }

    [Serializable]
    public class DisqusServiceSerializationException<TDestination> : DisqusServiceException
    {
        public string Json { get; private set; }
        public Type DestinationType { get; private set; }

        public DisqusServiceSerializationException(string json, string message, Exception inner) : base("WrongType", message, inner)
        {
            if (json == null) throw new ArgumentNullException("json");
            Json = json;
            DestinationType = typeof (TDestination);
        }

        protected DisqusServiceSerializationException(
            SerializationInfo info,
            StreamingContext context) : base(info, context)
        {
        }
    }
}